package app.sys.data.comm;

public enum ApiCode {
    /**
     *
     */

    SUCCESS("0000","操作成功"),

    UNAUTHORIZED("401","非法访问"),
    FAIL_PERMISSION("499","密码错误"),
    NOT_PERMISSION("403","没有权限"),

    NOT_FOUND("404","你请求的资源不存在"),

    NOT_FOUND_USER("999","账号不存在"),

    EXIT_USER("999","账号已存在"),

    FAIL("9999","操作失败"),

    LOGIN_EXCEPTION("4000","登陆失败"),

    SYSTEM_EXCEPTION("5000","系统异常"),

    /**
     * 参数校验级Code: 5001 - 6000
     */
    PARAMETER_EXCEPTION("5001","请求参数校验异常"),

    /**
     * 业务级Code: 6001 - 7000
     */
    USER_UNAUTHORIZED("6001","未授权，请先授权再访问"),

    USER_TWO_PASSWORDS_INCONSISTENT("6002","两次输入密码不一致"),

    USER_ACCOUNT_REGISTERED("6003","该账号已被注册"),
            ;

    private final String status;
    private final String msg;

    ApiCode(final String status, final String msg) {
        this.status = status;
        this.msg = msg;
    }

    public static ApiCode getApiCode(String code) {
        ApiCode[] ecs = ApiCode.values();
        for (ApiCode ec : ecs) {
            if (ec.getStatus() == code) {
                return ec;
            }
        }
        return SUCCESS;
    }

    public String getStatus() {
        return status;
    }

    public String getMsg() {
        return msg;
    }
}
